"""
@title(TenX腾晓2024年11月考核答题文件)
@warning(请勿修改参数和返回值)
@warning(请认真填写__init__中的数据)
@author(1323230180)
"""
from typing import List, Tuple


class TenXClass:
    def __init__(self):
        self.name = "林清华"
        self.id = "3124002016"

    @staticmethod
    def question1(n: int) -> list[str]:
        print(n)  # 打印，防止IDE警告

        def quaternary(n):
            li = []
            while n != 0:
                li.append(str(n % 4))
                n //= 4

            li.reverse()
            return "".join(li)

        arr= []
        for i in range(1,n+1):
            arr.append(quaternary(i))


        return arr

    @staticmethod
    def question2() -> list[tuple[int, int, int]]:
        answer = []
        for x in range(20,-1,-1):
            for y in range(1,35):
                for z in range(1,35):
                    if 5*x+3*y+z == 100 and x+y+3*z == 100:
                        answer.append((x,y,3*z))    

        return answer

    @staticmethod
    def question3(equipment: list[str], prop: list[str], material: list[str], items: list[str]) -> dict[str, list[str]]:
        print(equipment, prop, material, items)  # 打印，防止IDE警告
        #coding=gbk

        dic = {
            "equipment":[],
            "prop":[],
            "material":[],
        }


        def thing_sort(dic,li):
            for i in li:
                if i in equipment:
                    dic['equipment'].append(i)
                elif i in prop:
                    dic['prop'].append(i)
                elif i in material:
                    dic['material'].append(i)


        thing_sort(dic,items)

        return dic

    @staticmethod
    def question4(item_values: dict[str, int], items: list[str]) -> tuple[list[str], int]:
        print(item_values, items)  # 打印，防止IDE警告

        def find_max(dic,opt,r=3):
            keys = []
            values = []

            #为商品制作原始列表
            for key,value in dic.items():
                keys.append(key)
                values.append(value)

            #根据价格对商品排序(高到低)
            for i in range(len(keys)-1):
                for j in range(i+1,len(keys)):
                    if values[j] > values[i]:
                        keys[j],keys[i] = keys[i],keys[j]
                        values[j],values[i] = values[i],values[j]
    
            chosed = []
            s = 0 
            for k in keys:
                if r == 0:
                    break

                for q in opt:
                    if r == 0:
                        break

                    if k == q:
                        chosed.append(q)
                        l = keys.index(q)
                        s += values[l]
                        r -= 1
        
            return (chosed,s)


        return find_max(item_values,items)

    @staticmethod
    def question5(matrix: list[list[int]]) -> list[tuple[int, int]]:
        print(matrix)  # 打印，防止IDE警告

        def find_zero(li):
            answer = []
   
            for x,i in enumerate(li):
                for y,j in enumerate(i):
                    if j == 0:
                        answer.append((x+1,y+1))

            return answer

        return find_zero(matrix)
